package com.um2.mauction.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;


//@Entity
@Entity
public class Utilisateur implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id_user;
	
	private String login;	
	private String motdepasse;	
	private String nom;
	private String prenom;
	private String adresse;
	private String email;
	// the cmr fields
	

	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="bidder",targetEntity=Enchere.class)
	private Set<Enchere> bids = new HashSet<Enchere>();	
	
	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER, mappedBy="seller", targetEntity=Vente.class)
	private Set<Vente> ventes = new HashSet<Vente>();	
	
	//@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER, targetEntity=Commande.class, mappedBy="order_id")
	//private Set<Commande> commandes = new HashSet<Commande>();	
	
	
//	public Set<Commande> getCommandes() {
//		return commandes;
//	}
//
//
//	public void setCommandes(Set<Commande> commandes) {
//		this.commandes = commandes;
//	}


	public int getId_user() {
		return id_user;
	}


	public String getMotdepasse() {
		return motdepasse;
	}

	public Utilisateur(){
		
	}

	public Utilisateur(String login,String motdepasse,String nom,String prenom,String adresse,String email)
	{
		this.login = login;
		this.motdepasse = motdepasse;
		this.nom = nom;
		this.prenom = prenom;
		this.adresse = adresse;
		this.email = email;
	}

	public String getLogin() 
	{
		return this.login;
	}

	public void setLogin(String login)
	{
		this.login = login;
	}

	public String getMotDePasse()
	{
		return this.motdepasse;
	}

	public void setMotDePasse(String motDePasse) 
	{
		this.motdepasse = motDePasse;
	}

	public String getNom() 
	{
		return this.nom;
	}

	public void setNom(String nom) 
	{
		this.nom = nom;
	}

	public String getPrenom() 
	{
		return this.prenom;
	}

	public void setPrenom(String prenom) 
	{
		this.prenom = prenom;
	}

	public String getAdresse()
	{
		return this.adresse;
	}

	public void setAdresse(String adresse) 
	{
		this.adresse = adresse;
	}

	public String getEmail() 
	{
		return this.email;
	}

	public void setEmail(String email) 
	{
		this.email = email;
	}
	
	// The access methods for cmr fields
	
	public Set<Enchere> getBids()
	{
		return this.bids;
	}
	
	public void setBids(Set<Enchere> encheres)
	{
		this.bids = encheres;
	}
	
	
	public Set<Vente> getVentes()
	{
		return this.ventes;
	}
	
	public void setVentes(Set<Vente> ventes)
	{
		this.ventes = ventes;
	}
	
	// Business methods
	public void assignEnchere(Enchere e) 
	{
		if (this.bids == null) 
		{
			this.bids = new HashSet<Enchere>();
		}
		e.setBidder(this);
		this.bids.add(e);
	}
	
	public void assignVente(Vente v) 
	{
		if (this.ventes == null) 
		{
			this.ventes = new HashSet<Vente>();
		}
		v.setSeller(this);
		this.ventes.add(v);
	}


	public void setId_user(int id_user) {
		this.id_user = id_user;
	}
}